package lights;
/*
 * Author : rendyjr
 * Date	  : Jun 10, 2011
 * 6.005 Elements of Software Construction
 * Rendy Bambang Junior
 * rendy.jr@gmail.com
 * 
 * JUnit test file for ColoredLight.
 * It tests :
 * - constructor
 * - set method
 * - random method
 * 
 */

import java.awt.Color;

import org.junit.Assert;
import org.junit.Test;

public class ColoredLightTest {
	@Test public void makeRedLight(){
		ColoredLight cl = new ColoredLight(Color.red);
		Assert.assertEquals(cl.getColor(), Color.red);
	}
	
	@Test public void setBlueLight(){
		ColoredLight cl = new ColoredLight(Color.red);
		cl.setColor(Color.blue);
		Assert.assertEquals(cl.getColor(), Color.blue);
	}
	
	@Test public void testRandomColor() {
		ColoredLight cl = new ColoredLight(Color.red);
		// Call randomChange up to 100 times.
		// Probabilistically, should turn on at some point.
		boolean lightChanged = false;
		boolean colorChanged = false;
		for (int i = 0; i < 100; i++) {
			cl.randomChange();
			if (cl.isOn()) 
				lightChanged = true;
			if (!cl.getColor().equals(Color.red))
				colorChanged = true;
			if(lightChanged && colorChanged)
				break;
		}
		Assert.assertTrue(lightChanged && colorChanged);
	}
}
